
import { sandbox } from '@/libs/util'
import selectOptions from '@/publicComponents/selectOptions/index'

export default {
  props: {
    mode: {
      type: String,
      default: ''
    },
  },
  components: { selectOptions },

  data() {
    return {
      btnLoading: false,
      rules: {},
      form: sandbox({})
    };
  },
  methods: {
    AddRow () {
      return Promise.resolve()
    },
    UpdateRow () {
      return Promise.resolve()
    },
    SetData(row){
      Object.assign(this.form, row)
    },
    // closeForm
    closeForm (isReload= '') {
      this.$emit('close',isReload)
      this.btnLoading = false
      this.$refs.drawerForm && this.$refs.drawerForm.resetFields()
      this.form.reset()
    },
    handleSubmit () {
      this.$refs.drawerForm.validate(valid => {
        if (valid) {
          let form = sandbox(this.form)
          this.btnLoading = true
          ;(this.mode === 'add' ? this.AddRow() : this.UpdateRow())
              .then(() => {
                this.closeForm('reload')
              })
              .finally(() => {
                this.btnLoading = false
              })
        }
      })
    }
  }
}
